/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package be.ugent.medirem.persistence.entity;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;
import javax.persistence.Temporal;

/**
 *
 * @author Simon
 */
@Entity
@NamedQueries({
    // TODO : check query
    @NamedQuery(name="Consultation.findByGp", query="SELECT c FROM Consultation c WHERE c.gp.id = :gp"),
    @NamedQuery(name="Consultation.findByPatient", query="SELECT c FROM Consultation c WHERE c.patient.id = :patient"),
    // TODO : add dateTime > new Date() AND LIMIT 1,1
    @NamedQuery(name="Consultation.findNextConsultation", query="SELECT c FROM Consultation c WHERE c.patient.id = :patient AND c.gp.id = :gp AND c.dateTime > ':date'"),
    @NamedQuery(name="Consultation.findPreviousConsultation", query="SELECT c FROM Consultation c WHERE c.patient.id = :patient AND c.gp.id = :gp AND c.dateTime < ':date'"),
    @NamedQuery(name="Consultation.findConsultationsFromPatientWithGp", query="SELECT c FROM Consultation c WHERE c.patient.id = :patient AND c.gp.id = :gp")
})
public class Consultation implements Serializable {


    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    @OneToOne
    private GeneralPractitioner gp;
    @OneToOne
    private Patient patient;
    @Temporal(javax.persistence.TemporalType.TIMESTAMP)
    private Date dateTime;

    public Consultation() {
    }

    
    public Consultation(GeneralPractitioner gp, Patient p, Date date) {
        this.gp = gp;
        this.patient = p;
        this.dateTime = date;
    }

    /**
     * @return the id
     */
    public Long getId() {
        return id;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @return the gp
     */
    public GeneralPractitioner getGp() {
        return gp;
    }

    /**
     * @param gp the gp to set
     */
    public void setGp(GeneralPractitioner gp) {
        this.gp = gp;
    }

    /**
     * @return the patient
     */
    public Patient getPatient() {
        return patient;
    }

    /**
     * @param patient the patient to set
     */
    public void setPatient(Patient patient) {
        this.patient = patient;
    }

    /**
     * @return the date
     */
    public Date getDate() {
        return dateTime;
    }

    /**
     * @param date the date to set
     */
    public void setDate(Date date) {
        this.dateTime = date;
    }
}
